package cn.scxy.bookcity.controller;

import cn.scxy.bookcity.pojo.dto.AdminGoodsDTO;
import cn.scxy.bookcity.pojo.entity.Imgs;
import cn.scxy.bookcity.pojo.vo.*;
import cn.scxy.bookcity.service.AdminGoods;
import cn.scxy.bookcity.service.IUserIndexService;
import cn.scxy.bookcity.web.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 张正荣
 */
@RestController
@RequestMapping("/adminGoodsAddNew")
@Api(tags = "管理员商品管理")
@Slf4j
public class AdminGoodsAddNew {
    @Autowired
    AdminGoods adminGoods;
    @ApiOperation("[不用了]查询级联面板所需数据")
    @ApiOperationSupport(order = 3300)
    @GetMapping("/adminSelectGoodsAddNew")
    public JsonResult<List<AdminGoodsCateList>> adminSelectGoodsAddNew(){
        List<AdminGoodsCateList> adminGoodsCateLists = adminGoods.adminSelectGoodsAddNew();
        return JsonResult.ok(adminGoodsCateLists);
    }
 @ApiOperation("查询出版社")
    @ApiOperationSupport(order = 301)
    @GetMapping("/selectPressList")
    public JsonResult<List<PressListVO>> selectPressList(){
     List<PressListVO> pressListVOS = adminGoods.selectPressList();
     return JsonResult.ok(pressListVOS);
    }
 @ApiOperation("查询包装类型")
    @ApiOperationSupport(order = 302)
    @GetMapping("/selectPackList")
    public JsonResult<List<PackListVO>> selectPackList(){
     List<PackListVO> packListVOS = adminGoods.selectPackList();
     return JsonResult.ok(packListVOS);
    }

    @ApiOperation("根据名字查询包装id")
    @ApiOperationSupport(order =304)
    @GetMapping("/{id}/packByid")
    public JsonResult<String> packByid(@PathVariable Long id){
        String name = adminGoods.packByid(id);
        return JsonResult.ok(name);
    }
    @ApiOperation("根据名字查询出版社id")
    @ApiOperationSupport(order =305)
    @GetMapping("/{id}/pressByid")
    public JsonResult<String> pressByid(@PathVariable Long id){
        String name= adminGoods.pressByid(id);
        return JsonResult.ok(name);
    }

 @ApiOperation("添加商品信息")
    @ApiOperationSupport(order =305)
    @PostMapping("/add-new")
    public JsonResult<Void> addNewDTO(AdminGoodsDTO adminGoodsDTO){
        log.debug("adminGoodsDTO={}",adminGoodsDTO);
        adminGoods.insert(adminGoodsDTO);
        return JsonResult.ok();
    }
    @ApiOperation("查询商品信息")
    @ApiOperationSupport(order =306)
    @GetMapping("/goodslist")
    public JsonResult<List<GoodsListItemVO>> goodslist(){
        List<GoodsListItemVO> goodsListItemVO=adminGoods.selectgoodslist();
        return JsonResult.ok(goodsListItemVO);
    }

  @ApiOperation("删除商品信息和商品对应图片")
    @ApiOperationSupport(order =306)
    @PostMapping("/{id}/delete")
    public JsonResult<Void> delete(@PathVariable Integer id){
       adminGoods.deleteGoodsById(id);
        return JsonResult.ok();
    }
    @ApiOperation("启用类别")
    @ApiOperationSupport(order = 310)
    @ApiImplicitParam(name = "id", value = "类别id", required = true, dataType = "long")
    @PostMapping("/state/{id:[0-9]+}/enable")
    public JsonResult<Void> setEnable(@PathVariable Integer id) {
        log.debug("开始处理【启用类别】的请求，参数：{}", id);
        adminGoods.setEnable(id);
        return JsonResult.ok();
    }

    // http://localhost:8080//9527/disable
    @ApiOperation("禁用类别")
    @ApiOperationSupport(order = 311)
    @ApiImplicitParam(name = "id", value = "类别id", required = true, dataType = "long")
    @PostMapping("/state/{id:[0-9]+}/disable")
    public JsonResult<Void> setDisable(@PathVariable Integer id) {
        log.debug("开始处理【禁用类别】的请求，参数：{}", id);
        adminGoods.setDisable(id);
        return JsonResult.ok();
    }
    @ApiOperation("根据id查询商品信息")
    @ApiOperationSupport(order = 311)
    @ApiImplicitParam(name = "id", value = "类别id", required = true, dataType = "long")
    @GetMapping("/{id:[0-9]+}/selectGoodsById")
    public JsonResult<GoodsListItemVO> selectGoodsById(@PathVariable Integer id) {
        log.debug("开始处理根据id查询商品信息{}", id);
       GoodsListItemVO goodsListItemVO= adminGoods.selectGoodsById(id);
        return JsonResult.ok(goodsListItemVO);
    }
 @ApiOperation("根据id查询图片信息")
    @ApiOperationSupport(order = 311)
    @ApiImplicitParam(name = "id", value = "类别id", required = true, dataType = "long")
    @GetMapping("/{id:[0-9]+}/selectImgById")
    public JsonResult<List<ImgsListItemVO>> selectImgById(@PathVariable Integer id) {
        log.debug("开始处理根据id查询商品信息{}", id);
     List<ImgsListItemVO> imgsListItemVO= adminGoods.selectImgById(id);
        return JsonResult.ok(imgsListItemVO);
    }
    @ApiOperation("根据id删除图片信息")
    @ApiOperationSupport(order = 311)
    @ApiImplicitParam(name = "id", value = "类别id", required = true, dataType = "long")
    @PostMapping("/{id:[0-9]+}/deleteUrlById")
    public JsonResult<Void> deleteUrlById(@PathVariable Integer id) {
        log.debug("根据id删除图片信息{}", id);
        adminGoods.deleteUrlById(id);
        return JsonResult.ok();
    }
    @ApiOperation("根据id删除包装信息")
    @ApiOperationSupport(order = 311)
    @PostMapping("/{id:[0-9]+}/deletePack")
    public JsonResult<Void> deletePack(@PathVariable Integer id) {
        log.debug("根据id删除包装信息{}", id);
        adminGoods.deletePack(id);
        return JsonResult.ok();
    }
    @ApiOperation("根据id删除出版社信息")
    @ApiOperationSupport(order = 311)
    @PostMapping("/{id:[0-9]+}/deletePress")
    public JsonResult<Void> deletePress(@PathVariable Integer id) {
        log.debug("根据id删除出版社信息{}", id);
        adminGoods.deletePress(id);
        return JsonResult.ok();
    }
    @ApiOperation("根据商品id添加图片信息")
    @ApiOperationSupport(order = 311)

    @PostMapping("/insertUrl")
    public JsonResult<Void> insertUrl( ImgsListItemVO imgsListItemVO) {
        log.debug("根据商品id添加图片信息{},",imgsListItemVO);
        adminGoods.insertUrl(imgsListItemVO);
        return JsonResult.ok();
    }
    @ApiOperation("修改商品信息")
    @ApiOperationSupport(order = 311)
    @PostMapping("/updateGoods")
    public JsonResult<Void> updateGoods(GoodsListItemVO goodsListItemVO) {
        log.debug("修改商品信息{}",goodsListItemVO );
     adminGoods.updateGoods(goodsListItemVO);
        return JsonResult.ok();
    }
    @ApiOperation("模糊查询商品信息")
    @ApiOperationSupport(order = 311)
    @PostMapping("/selectLikeGoods")
    public JsonResult<List<GoodsListItemVO>> selectLikeGoods(GoodsListItemVO goodsListItemVO) {
        log.debug("修改商品信息{}",goodsListItemVO );
     List<GoodsListItemVO> list=adminGoods.selectLikeGoods(goodsListItemVO);
        return JsonResult.ok(list);
    }
    @ApiOperation("统计商品信息")
    @ApiOperationSupport(order = 311)
    @GetMapping("/selectGoodsCount")
    public JsonResult<Integer> selectGoodsCount() {
      int i=adminGoods.selectGoodsCount();
        return JsonResult.ok(i);
    }
    @ApiOperation("查询包装信息")
    @ApiOperationSupport(order = 311)
    @GetMapping("/packlist")
    public JsonResult<List<PackListVO>> packlist() {
        List<PackListVO> i=adminGoods.packlist();
        return JsonResult.ok(i);
    }
    @ApiOperation("查询出版社信息")
    @ApiOperationSupport(order = 311)
    @GetMapping("/presslist")
    public JsonResult<List<PressListVO>> presslist() {
        List<PressListVO> i=adminGoods.presslist();
        return JsonResult.ok(i);
    }
    @ApiOperation("修改包装信息")
    @ApiOperationSupport(order = 311)
    @PostMapping("/updatePackName")
    public JsonResult<Void> updatePackName(PackListVO packListVO) {
        log.debug("修改包装信息{}",packListVO );
        adminGoods.updatePackName(packListVO);
        return JsonResult.ok();
    }
    @ApiOperation("修改出版社信息")
    @ApiOperationSupport(order = 311)
    @PostMapping("/updatePressName")
    public JsonResult<Void> updatePressName(PressListVO pressListVO) {
        log.debug("修改出版社信息{}",pressListVO );
        adminGoods.updatePressName(pressListVO);
        return JsonResult.ok();
    }
    @ApiOperation("添加出版社信息")
    @ApiOperationSupport(order = 311)
    @PostMapping("/insetPress")
    public JsonResult<Void> insetPress(PressListVO pressListVO) {
        log.debug("修改出版社信息{}",pressListVO);
        adminGoods.insetPress(pressListVO);
        return JsonResult.ok();
    }
    @ApiOperation("添加包装信息")
    @ApiOperationSupport(order = 311)
    @PostMapping("/insetPack")
    public JsonResult<Void> insetPack(PackListVO packListVO) {
        log.debug("修改出版社信息{}",packListVO);
        adminGoods.insetPack(packListVO);
        return JsonResult.ok();
    }



}
